Repository navigation
feat(agents): 插件注入模型清单,Core 管模型的显示开关和推理强度、速度的选择 - #263
Conversation
f191ff9 to
877bf0a
Compare
877bf0a to
5bb7cf7
Compare
| let model = differs(&self.model, snapshot.model.as_ref().map(|m| m.id.as_str())); | ||
| let effort = differs( | ||
| &self.effort, | ||
| snapshot.effort.as_ref().map(|e| e.id.as_str()), | ||
| ); | ||
| let speed = differs(&self.speed, snapshot.speed.as_ref().map(|s| s.id.as_str())); | ||
| if let Some(model) = model { | ||
| let change = ProviderChange::SetModel { | ||
| model, | ||
| effort, | ||
| speed, | ||
| }; |
There was a problem hiding this comment.
🔴 Model plans silently lose selected levels
When a plan switches models, selection_changes drops requested levels that match the current model’s defaults. The new model can use different defaults. Staged verification accepts those values because the edit omitted the requested levels.
Learn more
read_model_settings saves the effective effort and speed, including defaults. A default is not a setting in the file; the CLI derives it from the selected model. During a model switch, check_selection lets omitted default levels follow the new model. shows_in then verifies only levels the edit carried.
Example: Save a plan for Model A with medium effort. Switch to Model B, whose default is also medium, after setting Model A’s saved effort explicitly to medium even though Model A defaults to low. Applying the original plan from Model B omits medium, and Model A runs at low if neither model has an explicit effort in effect in the current configuration. More directly, a plan requesting Model A at medium applied from any model defaulting to medium succeeds without restoring the requested level when Model A defaults to low.
Recommended fix: Compare requested levels with the effective values after the proposed switch, not just with the current model’s values. Carry levels that would differ, and verify all explicitly requested values on the staged snapshot before committing.
Was this helpful? React with 👍 or 👎 to provide feedback.
| let mut changed = false; | ||
| for (op, change) in changes { | ||
| changed |= self.apply_providers_checked(runtime, agent, op, change)?; | ||
| } | ||
| let hidden = settings.hidden; | ||
| changed |= self.change_hidden(runtime, agent, |_, _| Ok(hidden))?; |
There was a problem hiding this comment.
🔴 Partial writes from rejected model plans
apply_model_settings_checked commits model selections before checking whether the CLI menu has an editable target. When menu sync returns noTarget, only the hidden switches roll back. The plan fails, but the CLI keeps the new selection.
Learn more
A model plan groups the CLI selection with the list of models hidden in Lithe. The preflight validates only selection operations; each subsequent apply_providers_checked call can commit its own file. change_hidden runs afterwards and restores only its own visibility write on failure. edit_providers rejects a missing model-menu target before calling the backend.
Example: An agent reports an editable model file and the current CLI menu, but no editable menu target in its current configuration. Apply a plan that changes the model from A to B and hides C. Core commits B and then reports agentProviders.noTarget; C is still visible.
Recommended fix: Preflight the visibility file and required menu target before committing selections. Stage and verify all requested changes before committing the group, combining changes that share a target; ensure a later failure cannot leave earlier writes committed without a partial-result response.
Was this helpful? React with 👍 or 👎 to provide feedback.
| if edited.is_err() && saved { | ||
| let _writing = self.lock_writing(); | ||
| // The plugin's refusal is what the user needs to see; switches | ||
| // that cannot be put back read as the user just set them. | ||
| // log-exempt: Same failure already recorded: this put-back follows the menu edit failure returned below, which the command logs as agent.providers.change_failed and the request trace records; switches it cannot put back stay as the user set them, and Lithe's pickers show them. | ||
| let _ = store(&config, &key, &before); | ||
| } |
There was a problem hiding this comment.
🔴 Failed toggle erases saved visibility changes
When a second toggle commits while the first menu edit is pending, change_hidden can roll back both toggles. edit_staged rejects the first edit as stale, but its rollback overwrites the newer switches. The CLI keeps the newer menu.
Learn more
change_hidden saves hidden models under a write lock, then releases it before calling the plugin. The agent dispatcher does not serialize requests. A later toggle can read and update the same hidden records while the first staged edit is awaiting its plugin response. If the later edit commits first, edit_staged rejects the earlier staged copy because the CLI file changed. The earlier call then restores its original hidden list, overwriting the successful update.
Example: Hide A and let Core stage the CLI edit. While that edit is pending, hide B in another request and let it finish. The CLI hides A and B. The first edit then fails the file comparison and restores the empty hidden list, so both models reappear in Lithe.
Recommended fix: Make updates to an agent’s hidden list and CLI menu one serialized or revision-checked transaction. Avoid publishing tentative visibility records that another request can build on; a failed edit must not overwrite any later committed update.
Was this helpful? React with 👍 or 👎 to provide feedback.
| if in_menu == Some(shown.iter().collect()) { | ||
| return Ok(saved); | ||
| } | ||
| let menu = ProviderChange::SetModelMenu { models: shown }; | ||
| let edited = self.edit_providers( | ||
| runtime, | ||
| agent, | ||
| &config, | ||
| &paths, | ||
| &snapshot, | ||
| &menu, | ||
| json!(menu), | ||
| None, | ||
| ); |
There was a problem hiding this comment.
🟡 Unchanged CLI menu passes toggle verification
When the CLI menu differs but the plugin edits nothing, change_hidden still reports a successful visibility change. edit_staged skips verification for no-op edits. Lithe hides the model, but the CLI still lists it.
Learn more
Core compares the requested menu with the current menu before sending a staged edit. edit_staged returns Ok(false) without readback if the backend reports changed: false or the staged bytes match the original. The caller rolls back the stored switches only on an error, so it treats this result as success for visibility even though the desired menu was never verified.
Example: The CLI lists A and B. The user hides B, and the plugin reports changed: false without updating the menu. Lithe hides B and returns changed: true, but the CLI still shows B.
Recommended fix: For a menu edit, verify the effective menu even when the staged helper would normally return a no-op. If it does not match, return agentProviders.editNotApplied and restore the hidden switches.
Was this helpful? React with 👍 or 👎 to provide feedback.
关联
改动
都是 API-45、
agents能力 0 内的补充,不升版本。插件后端协议沿用 providers 的read/edit,没有新增插件函数;四个 SDK 都没有 providers 的类型化代码,只更新了 README 说明。一、插件注入模型清单
read快照新增以下字段:models:每项{id, name?, provider?, efforts?, defaultEffort?, speeds?, defaultSpeed?, contextWindow?, description?};efforts、speeds:CLI 提供的推理强度和速度档,每项{id, name?};effort、speed:正在用的值,每项{id, source?},source是来源层;modelMenu与targets.modelMenu:CLI 自己的模型菜单。provider必须是快照里的供应商;contextWindow取 1..=1e9;description最长 1024 字符;efforts、speeds 各最多 16 项;modelMenu必须是清单的子集。二、显示开关
models.json,仅所有者可读写,不含机密。setModelMenu时,Core 通过暂存副本让插件把显示的模型写进 CLI 的菜单:写前先备份,写失败就把开关恢复原状。没有声明时,开关只影响 Lithe 的选择器。agentProviders.showModels {agent, show?, hide?},回答{changed}。只接受用户发起的请求;show、hide各最多 512 个,至少给一个,同一 ID 不能两边都出现。三、选择
agentProviders.apply的setModel可以带effort、speed,需要插件也声明了setEffort、setSpeed;另新增setEffort、setSpeed两种操作。unknownModel、unknownEffort、unknownSpeed;unsupportedCombination:只能用模型列出的强度和速度;换模型时,沿用的强度和速度也要新模型支持。来源层为default的值随模型变化,不做检查。apply发setModelMenu会被拒,错误码invalidChange。四、整组读写(给以后的“方案”用)
agentProviders.readModelSettings {agent}读出{settings: {hidden, model?, effort?, speed?}}。agentProviders.applyModelSettings {agent, settings}整组写回:先检查全部修改,有一项被拒就什么都不改。只接受用户发起的请求。五、错误码与日志
agentProviders.unknownModel、unknownEffort、unknownSpeed(entry_not_found),以及agentProviders.unsupportedCombination(invalid_request)。configuration.providers.operations新增setEffort、setSpeed、setModelMenu。agent.providers.change_applied、change_failed的change新增取值showModels、applyModelSettings;没有新事件。六、文档
agents.plugin.json,新增 fixturefixtures/agents/model-catalog.json;rust/contracts/rust-core-api.md;domains/agents.md(中英);agents0 行;library.rs模块文档里资源库目录的文件清单,加上saved-providers.json和models.json;record-read.json。对宿主的影响
PINNED_CORE_REVISION升到本 PR 的合入提交。要做的有:setModel里带上新模型的defaultEffort,速度同理。read里报models、efforts、speeds、当前effort、speed;setEffort、setSpeed;setModelMenu。验证
本机 macOS arm64,基于 main 3351f74(含 #262):
cargo test --locked -p lithe-agent-runtime -p lithe-plugin-agents -p lithe-corecargo clippy --locked --workspace --all-targets -- -D warnings、cargo fmt --all -- --checkLIBSQLITE3_SYS_USE_PKG_CONFIG=1 cargo clippy --target x86_64-pc-windows-msvclithe-core经插件市场依赖zstd-sys,本机缺 Windows C 头文件编不了,留给 CIverify-docs.mjsgenerate-log-events.mjs --checkverify-rust-core-comments.shverify-platform-tests.mjssdk-e2e.mjs新测试覆盖:
已变基到含 #262 的 main:API 总表和能力版本表的 API-45、
agents0 行保留 #262 的会话说明,本 PR 的模型清单接在后面;协议更新记录里已合入的 #262 移进时间线 2026-12-03,“待合入”只剩本 PR。